package edu.zut.cs.software.perfect.course.service.impl;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import java.util.List;
import java.util.Optional;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.zut.cs.software.perfect.base.service.impl.GenericManagerImpl;
import edu.zut.cs.software.perfect.course.dao.CourseInformationDao;
import edu.zut.cs.software.perfect.course.domain.CourseInformation;
import edu.zut.cs.software.perfect.course.service.CourseInformationManager;
/**
 * @ClassName courseInformationManagerImpl
 * @Description TODO
 * @Author xiaoyingzi
 * @Date 2020年3月17日 下午5:38:05
 * @Version 1.0
 */
@Service("courseInformationManager")
@Transactional
public class CourseInformationManagerImpl extends GenericManagerImpl<Long, CourseInformation> implements CourseInformationManager {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = LogManager.getLogger(CourseInformationManagerImpl.class.getName());

	CourseInformationDao courseInformationDao;
	
	@Autowired
	public void setCourseInformationDao(CourseInformationDao courseInformationDao) {
		this.courseInformationDao = courseInformationDao;
		this.dao = this.courseInformationDao;
	}
	@Override
	public List<CourseInformation> findAll(){
		return (List<CourseInformation>) this.dao.findAll();
	}

//	@Override
//	public List<CourseInformation> findByFullname(String string) {
//		// TODO Auto-generated method stub
//		return null;
//	}


	@Override
	public Optional<CourseInformation> findByCourseId(Long courseId) {
		// TODO Auto-generated method stub
		Optional<CourseInformation> result = this.dao.findById(courseId);
		return result;
	}
	
	@Override
	public Boolean deleteById(Long courseId) {
		// TODO Auto-generated method stub
		Optional<CourseInformation> courseInformation = this.dao.findById(courseId);
		if(courseInformation.equals(Optional.empty())) {
			return false;
		} else {
			this.dao.delete(courseInformation.get());
			return true;
		}
	}
}
